package com.example.siyun.controller.logincontroller;


import com.example.siyun.service.ex.*;
import com.example.siyun.util.JsonResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
/**
 * @Auther: 全
 * @Date: 2022/9/26 09:33
 * @Description: 异常基类的控制层
 */
public class BaseController {
    public static final int OK=200;
    @ExceptionHandler(ServiceException.class)
    public JsonResult<Void> handleException(Throwable e){
        JsonResult<Void> result=new JsonResult<>();
        if(e instanceof UsernameDuplicatedException){
            result.setState(4000);
            result.setMessage("用户名已经被占用");
        }else if(e instanceof InsertException){
            result.setState(5000);
            result.setMessage("插入时产生了未知的异常");
        }else if(e instanceof UserNotFoundException){
            result.setState(5001);
            result.setMessage("用户不存在");
        }else if(e instanceof PasswordNotMatchException){
            result.setState(5002);
            result.setMessage("用户密码错误");
        }
        return result;

    }

}
